package com.wxzz.elearing.pay.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.pay.dto.UserOrderDto;
import com.wxzz.elearing.pay.entity.UserOrder;
import com.wxzz.elearing.pay.service.IUserOrderService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wx-pay")
@Api(tags = "微信支付接口(小程序)")
public class WxPayController {

    @Autowired
    private IUserOrderService userOrderService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "订单列表(小程序)", notes = "订单列表(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listUserOrder", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<UserOrder>> listUserOrder(@RequestHeader String token, @RequestBody UserOrderDto userOrderDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        userOrderDto.setUserType(1);
        userOrderDto.setUserId(jsonObject.getLong("id"));
        return userOrderService.listUserOrder(userOrderDto);
    }

    @ApiOperation(value = "查询订单详情(小程序)", notes = "查询订单详情(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectUserOrderById/{userOrderId}", method = RequestMethod.POST)
    public ReturnVO<UserOrder> selectUserOrderById(@RequestHeader String token, @PathVariable Long userOrderId) {
        return userOrderService.selectUserOrderById(userOrderId);
    }
}
